<?php
// No direct access to this file
defined('_JEXEC') or die;
 
// import the list field type
jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
 
/**
 * NGMenu Form Field class for the NGMenu component
 */
class JFormFieldIconFiles extends JFormFieldList
{
	/**
	 * The field type.
	 *
	 * @var		string
	 */
	protected $type = 'IconFiles';
 
//	public function getLabel() {
//	}
 
	public function getInput() {
		$options = null;
		//build the list from all css files
		$relpath = 'modules'.DS.'mod_ngmenu'.DS.'mod_ngmenu'.DS.'images'.DS.'icon';
		$path = JPATH_ROOT.DS.$relpath;
		$folder = @dir($path);
		$values = array();
		$values[] = JHtml::_('select.option', '', JText::_('COM_NGMENU_LIST_VALUES_NONE2'));
		if ($folder) {
			while ($file = $folder->read()){
				if ($file != "." && $file != ".." && $file != "CVS" && is_file("$path/$file")){
					$relpath = str_replace( '\\', '/', $relpath );
					$values[] = JHtml::_('select.option', "/$relpath/$file", $file);
				}
			}
			$folder->close();
		}
		sort($values);
		
		if ($this->name == 'jform[icon_normal]'){
			$id = 'icon-normal';
		}
		if ($this->name == 'jform[icon_over]'){
			$id = 'icon-over';
		}
		
		$prefix = JURI::root(true);
		$placeholder = JURI::root().'modules/mod_ngmenu/mod_ngmenu/images/blank20.gif';
		$options = 'onChange="preview_icon(this, \''.$id.'\', \''.$placeholder.'\', \''.$prefix.'\')"';
		
		return JHtml::_('select.genericlist', $values, $this->name, $options, 'value', 'text', $this->value);
	}
}

